/*eslint-disable*/

import {getCusFmtTimeDate, getCustomFormatTimeDate} from "./TimeDate";

/**获取客户端软硬件简要信息*/
function clientBaseInfo() {
    let infoBody = {
        EnableCookie: navigator.cookieEnabled,
        EnableJava: navigator.javaEnabled(),
        appCodeName: navigator.appCodeName,
        appName: navigator.appName,
        appVersion: navigator.appVersion,
        client_Mozilla_version: undefined,
        client_AppleWebKit_version: undefined,
        client_Chrome_version: undefined,
        client_Safari_version: undefined,
        client_languageList: navigator.languages,
        client_languageUser: navigator.language,
        client_doNotTrack: false,
        client_vendor: navigator.vendor,
        client_mobile: false,
        client_mobile_code: undefined,
        client_onLine: navigator.onLine,
        system_build: undefined,
        system_model: undefined,
        system_name: undefined,
        system_platform: navigator.platform,
        system_processType: undefined,
        system_TouchScreen: false,
        system_window: undefined,
    }
    if (parseInt(navigator.doNotTrack) === 1) {
        infoBody.client_doNotTrack = true;
    }
    infoBody.system_TouchScreen = parseInt(`${navigator.maxTouchPoints}`) > 0;
    let tempData_appVersion = String(navigator.appVersion).split(" ");
    infoBody.client_Mozilla_version = tempData_appVersion[0];
    tempData_appVersion.shift();
    let tmp = [];
    let count = 0;
    let tms = 0;
    let existLeft = false;
    while (true) {
        if (String(tempData_appVersion[tms]).indexOf("(") > -1) {
            existLeft = true;
            if (typeof tmp[count] !== "object") {
                tmp[count] = [];
            }
            tmp[count].push(tempData_appVersion[tms]);
            tempData_appVersion.splice(tms, 1);
        } else if (String(tempData_appVersion[tms]).indexOf(")") > -1) {
            tmp[count].push(tempData_appVersion[tms]);
            tempData_appVersion.splice(tms, 1);
            count++;
            existLeft = false;
        } else {
            if (existLeft) {
                tmp[count].push(tempData_appVersion[tms]);
                tempData_appVersion.splice(tms, 1);
            } else {
                if (tms >= tempData_appVersion.length) {
                    break;
                }
                tms++;
            }
        }
    }
    for (let num in tmp) {
        tmp[num] = tmp[num].join(',');
        tmp[num] = String(tmp[num]).substr(1, String(tmp[num]).length - 2);
    }
    for (let num in tmp) {
        tmp[num] = String(tmp[num]).split(',');
        tmp[num] = String(tmp[num]).split(',');
    }
    for (let num in tmp) {
        tmp[num].forEach((value, index, array) => {
            switch (value) {
                case "":
                    array.splice(index, 1);
                    break;
                default:
                    if (String(value).indexOf("/") > -1) {
                        tempData_appVersion.push(value);
                        array.splice(index, 1);
                    }
                    break;
            }
        });
    }
    for (let num in tempData_appVersion) {
        if (String(tempData_appVersion[num]).indexOf("/") > -1) {
            let tmp = String(tempData_appVersion[num]).split("/");
            switch (String(tmp[0]).toLowerCase()) {
                case "applewebkit":
                    infoBody.client_AppleWebKit_version = tmp[1];
                    break;
                case "chrome":
                    infoBody.client_Chrome_version = tmp[1];
                    break;
                case "safari":
                    infoBody.client_Safari_version = tmp[1];
                    break;
                case "mobile":
                    infoBody.client_mobile = true;
                    infoBody.client_mobile_code = tmp[1];
                    break;
                case "build":
                    infoBody.system_build = tmp[1];
                    break;
                default:
                    infoBody[String(tmp[0]).toString()] = tmp[1];
                    break;
            }
        } else {
            switch (String(tempData_appVersion[num]).toLowerCase()) {
                case "mobile":
                    infoBody.client_mobile = true;
                    break;
            }
        }
    }
    if (infoBody.client_mobile) {
        infoBody.system_window = String(tmp[0][0]).substr(0, String(tmp[0][0]).length - 1);
        tmp[0].shift();
        let tmp1 = [], es = 0, ols = undefined;
        while (true) {
            if (String(tmp[0][es]).indexOf(";") > -1) {
                ols += " " + String(tmp[0][es]).substr(0, String(tmp[0][es]).length - 1);
                tmp1.push(ols);
                tmp[0].splice(0, (es + 1));
                es = 0;
                ols = undefined;
            } else {
                if (es > (tmp[0].length - 1)) {
                    tmp1.push(ols);
                    break;
                } else {
                    if (ols === undefined) {
                        ols = "";
                        ols += tmp[0][es];
                    } else {
                        ols += " " + tmp[0][es];
                    }
                }
                es++;
            }
        }
        infoBody.system_model = tmp1[1];
        infoBody.system_name = tmp1[0];
    } else {
        infoBody.system_window = String(tmp[0][0]).substr(0, String(tmp[0][0]).length - 1);
        tmp[0].splice(0, 1);
        infoBody.system_processType = tmp[0][1];
        infoBody.system_name = tmp[0][0];
    }
    return infoBody;
}

/**端口范围检测*/
function portRange(Port) {
    let FinalDetectValue = false;
    if (Object.prototype.toString.call(Port) === "[object Number]" && !isNaN(Port) && isFinite(Port)) {
        if (parseInt(Port) > 1 && parseInt(Port) < 65535) {
            FinalDetectValue = true;
        }
    }
    return FinalDetectValue;
}

export {
    clientBaseInfo,
    getCusFmtTimeDate,
    getCustomFormatTimeDate,
    portRange
};